package mylibrary.thread.produce_consume;

import java.util.ArrayList;
import java.util.List;

public class Plate {

	List eggs = new ArrayList();
	
	public synchronized Object getEgg() {
		
		while(eggs.size() == 0) {
			try {
				wait();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		Object egg = eggs.get(0);
		eggs.clear();
		notify();
		
		System.out.println("Get an egg");
		return egg;
	}
	
	public synchronized void putEgg(Object egg) {
		while(eggs.size() > 0) {
			try {
				wait();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		eggs.add(egg);
		notify();
		System.out.println("Put an egg");
	}
}
